﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GraphLibrary;
using GraphLibrary.Algorithms;

namespace TestProject1
{
    [TestClass]
    public class ConnectedComponents
    {
        DirectedGraph<int,Edge<int>> graph;
        ConnectedComponents<int, Edge<int>> cc;

        DirectedGraph<string, Edge<string>> graph1;
        ConnectedComponents<string, Edge<string>> cc1;

        [TestInitialize]
        public void BeforeTest()
        {
            graph = new DirectedGraph<int, Edge<int>>();
            cc = new ConnectedComponents<int,Edge<int>>(graph);
            for (int i = 1; i < 6; i++)
                graph.AddVertex(i);
            graph.AddEdge(new Edge<int>(1, 2));
            graph.AddEdge(new Edge<int>(2, 3));
            graph.AddEdge(new Edge<int>(1, 3));
            graph.AddEdge(new Edge<int>(3, 4));
            graph.AddEdge(new Edge<int>(2, 5));
            graph.AddVertex(6);
            graph.AddVertex(7);

            graph1 = new DirectedGraph<string, Edge<string>>();
            cc1 = new ConnectedComponents<string, Edge<string>>(graph1);
            graph1.AddVertex("New-York");
            graph1.AddVertex("London");
            graph1.AddVertex("Manchester");
            graph1.AddVertex("York");
            graph1.AddEdge(new Edge<string>("New-York","London"));
            graph1.AddEdge(new Edge<string>("London", "York"));
            graph1.AddEdge(new Edge<string>("York", "Manchester"));
            graph1.AddVertex("Moscow");
            graph1.AddVertex("Berlin");
            graph1.AddEdge(new Edge<string>("Moscow", "Berlin"));
        }

        [TestMethod]
        public void ConnectedComponentsTest1()
        {
            cc.Execute();
            CollectionAssert.AreEquivalent(new Dictionary<int, int>() { { 1, 1 }, { 2, 1 }, { 3, 1 }, { 4, 1 }, { 5, 1 },{6,2},{7,3} }, cc.Components);
        }

        [TestMethod]
        public void ConnectedComponentsTest2()
        {
            cc1.Execute();
            CollectionAssert.AreEquivalent(new Dictionary<string, int>() { { "New-York", 1 }, { "London", 1 }, { "Manchester", 1 }, { "York", 1 }, { "Moscow", 2 }, { "Berlin", 2 } }, cc1.Components);
        }

    }
}
